<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" href="${ctx}/css/common.css" />
<link rel="stylesheet" href="${ctx}/css/validate.css" />
<link rel="stylesheet" href="${ctx}/css/dialog/skin/bluebar/ymPrompt.css" />

<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/dialog/ymPrompt.js"></script>

<script language="javascript">
<c:if test="${action == 'SaveAdd'}">
ymPrompt.succeedInfo("<s:text name='AddAppSuccess' />！",null,null,null,refresh);
</c:if>
<c:if test="${action == 'SaveClose'}">
ymPrompt.succeedInfo("<s:text name='AddAppSuccess' />！",null,null,null,close);
</c:if>
<c:if test="${action == 'Update'}">
ymPrompt.succeedInfo("<s:text name='UpdateAppSuccess' />！",null,null,null,close);
</c:if>

$(document).ready(function() {
	$("#appName").focus();
});

//对话框回调方法
function close(tp){
	if(tp=="ok"){
		$("#mainFrame",window.parent.document).attr("src","appManagerPage.action");
		parent.ymPrompt.close();
	}
}

//关闭对话框
function closeWin(){
	parent.ymPrompt.close();
}

//刷新页面
function refresh(tp){
	if(tp=="ok"){
		window.location.href="editAppPage.action";
	}
}

function formSubmit(action){
	if(checkForm()){
		if(action == 1) { //保存新增
			$("#action").val("SaveAdd");
		} else if(action == 2){ //保存关闭
			$("#action").val("SaveClose");
		}
		$("#appForm").submit();
	} else {
		return false;
	}
}

function checkForm(){
	var appNameFlag = true;
	
	if($("#appName").val().replace(/\s+/g,'') == ""){
		$("#appName").addClass("error");
		$("#appNameErrMsg").text("<s:text name='AppNameIsNotNull' />");
		appNameFlag = false;
	} else {
		$("#appName").removeClass("error");
		$("#appNameErrMsg").text("*");
		appNameFlag = true;
	}
	
	if(appNameFlag){
		return true;
	} else {
		return false;
	}
}
</script>
</head>

<body>
<c:if test="${app == null}">
<form id="appForm" name="appForm" action="addApp.action" method="post" onsubmit="return $('#action').val() == 'SaveAdd'?formSubmit(1):formSubmit(2)">
</c:if>
<c:if test="${app != null}">
<form id="appForm" name="appForm" action="updateApp.action" method="post" onsubmit="return formSubmit(2)">
</c:if>
	<input id="id" name="id" type="hidden" value="${app.id }" />
	<input id="action" name="action" type="hidden" value="${action }" />
	<table width="100%" cellspacing="1" cellpadding="5" class="table_class">
		<tr>
			<td width="20%"><s:text name='AppName' />：</td>
			<td>
				<input id="appName" name="appName" type="text" value="${app.appName }" />
				<span id="appNameErrMsg" class="inputMsg">*</span>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<c:if test="${app == null}">
				<input id="submitBtn" name="submitBtn" type="button" onclick="formSubmit(1);" value="<s:text name='SaveAndAdd' />" />
				<input id="submitBtn" name="submitBtn" type="button" onclick="formSubmit(2);" value="<s:text name='SaveAndClose' />" />
				<input id="submitBtn" name="submitBtn" type="button" onclick="closeWin();" value="<s:text name='Close' />" />
				</c:if>
				<c:if test="${app != null}">
				<input id="submitBtn" name="submitBtn" type="button" onclick="formSubmit(2);" value="<s:text name='Save' />" />
				<input id="submitBtn" name="submitBtn" type="button" onclick="closeWin();" value="<s:text name='Close' />" />
				</c:if>
			</td>
		</tr>
	</table>
</form>
</body>

</html>
